home *** CD-ROM | disk | FTP | other *** search
/ United Public Domain Gold 2 / United Public Domain Gold 2.iso / utilities / pu247.dms / pu247.adf / Intuition / Gadgets / Example1.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  161 lines

  1. /***********************************************************/
  2. /*                                                         */
  3. /* Amiga C Encyclopedia (ACE) V3.0      Amiga C Club (ACC) */
  4. /* -------------------------------      ------------------ */
  5. /*                                                         */
  6. /* Book:    ACM Intuition               Amiga C Club       */
  7. /* Chapter: Gadgets                     Tulevagen 22       */
  8. /* File:    Example1.c                  181 41  LIDINGO    */
  9. /* Author:  Anders Bjerin               SWEDEN             */
  10. /* Date:    92-05-01                                       */
  11. /* Version: 1.10                                           */
  12. /*                                                         */
  13. /*   Copyright 1992, Anders Bjerin - Amiga C Club (ACC)    */
  14. /*                                                         */
  15. /* Registered members may use this program freely in their */
  16. /*     own commercial/noncommercial programs/articles.     */
  17. /*                                                         */
  18. /***********************************************************/
  19.  
  20. /* This program will open a normal window which is connected to the    */
  21. /* Workbench Screen. The window will use all System Gadgets, and will  */
  22. /* close first when the user has selected the System gadget Close      */
  23. /* window. (Same as Example3 in chapter 2 WINDOWS, except that we have */
  24. /* added an IDCMP check on the Close window gadget.)                   */
  25.  
  26. /* Extra information:                                                    */
  27. /* This program will quit first when the user has selected the Close     */
  28. /* window gadget. To tell Intuition that we want the System gadget Close */
  29. /* window to send us a message when the user selects it, we only need to */
  30. /* set the CLOSEWINDOW flag in the IDCMPFlags field.                     */
  31.  
  32.  
  33.  
  34. #include <intuition/intuition.h>
  35.  
  36.  
  37.  
  38. struct IntuitionBase *IntuitionBase;
  39.  
  40.  
  41.  
  42. /* Declare a pointer to a Window structure: */ 
  43. struct Window *my_window;
  44.  
  45. /* Declare and initialize your NewWindow structure: */
  46. struct NewWindow my_new_window=
  47. {
  48.   50,            /* LeftEdge    x position of the window. */
  49.   25,            /* TopEdge     y positio of the window. */
  50.   200,           /* Width       200 pixels wide. */
  51.   100,           /* Height      100 lines high. */
  52.   0,             /* DetailPen   Text should be drawn with colour reg. 0 */
  53.   1,             /* BlockPen    Blocks should be drawn with colour reg. 1 */
  54.   CLOSEWINDOW,   /* IDCMPFlags  The window will give us a message if the */
  55.                  /*             user has selected the Close window gad. */
  56.   SMART_REFRESH| /* Flags       Intuition should refresh the window. */
  57.   WINDOWCLOSE|   /*             Close Gadget. */
  58.   WINDOWDRAG|    /*             Drag gadget. */
  59.   WINDOWDEPTH|   /*             Depth arrange Gadgets. */
  60.   WINDOWSIZING|  /*             Sizing Gadget. */
  61.   ACTIVATE,      /*             The window should be Active when opened. */
  62.   NULL,          /* FirstGadget No Custom gadgets. */
  63.   NULL,          /* CheckMark   Use Intuition's default CheckMark. */
  64.   "CLOSE ME",    /* Title       Title of the window. */
  65.   NULL,          /* Screen      Connected to the Workbench Screen. */
  66.   NULL,          /* BitMap      No Custom BitMap. */
  67.   80,            /* MinWidth    We will not allow the window to become */
  68.   30,            /* MinHeight   smaller than 80 x 30, and not bigger */
  69.   300,           /* MaxWidth    than 300 x 200. */
  70.   200,           /* MaxHeight */
  71.   WBENCHSCREEN   /* Type        Connected to the Workbench Screen. */
  72. };
  73.  
  74.  
  75.  
  76. main()
  77. {
  78.   /* Boolean variable used for the while loop: */
  79.   BOOL close_me;
  80.  
  81.   /* Declare a variable in which we will store the IDCMP flag: */
  82.   ULONG class;
  83.   
  84.   /* Declare a pointer to an IntuiMessage structure: */
  85.   struct IntuiMessage *my_message;
  86.  
  87.  
  88.  
  89.   /* Before we can use Intuition we need to open the Intuition Library: */
  90.   IntuitionBase = (struct IntuitionBase *)
  91.     OpenLibrary( "intuition.library", 0 );
  92.   
  93.   if( IntuitionBase == NULL )
  94.     exit(); /* Could NOT open the Intuition Library! */
  95.  
  96.  
  97.  
  98.   /* We will now try to open the window: */
  99.   my_window = (struct Window *) OpenWindow( &my_new_window );
  100.   
  101.   /* Have we opened the window succesfully? */
  102.   if(my_window == NULL)
  103.   {
  104.     /* Could NOT open the Window! */
  105.     
  106.     /* Close the Intuition Library since we have opened it: */
  107.     CloseLibrary( IntuitionBase );
  108.  
  109.     exit();  
  110.   }
  111.  
  112.  
  113.  
  114.   /* We have opened the window, and everything seems to be OK. */
  115.  
  116.  
  117.  
  118.   close_me = FALSE;
  119.  
  120.   /* Stay in the while loop until the user has selected the Close window */
  121.   /* gadget: */
  122.   while( close_me == FALSE )
  123.   {
  124.     /* Wait until we have recieved a message: */
  125.     Wait( 1 << my_window->UserPort->mp_SigBit );
  126.  
  127.     /* Collect the message: */
  128.     my_message = (struct IntuiMessage *) GetMsg( my_window->UserPort );
  129.     /* Ahhh, these paranoid compilers... */
  130.  
  131.     /* Have we collected the message sucessfully? */
  132.     if(my_message)
  133.     {
  134.       /* After we have collected the message we can read it, and save any */
  135.       /* important values which we maybe want to check later: */
  136.       class = my_message->Class;
  137.  
  138.       /* After we have read it we reply as fast as possible: */
  139.       /* REMEMBER! Never try to read a message after you have replied! */
  140.       /* Some other process has maybe changed it. */
  141.       ReplyMsg( my_message );
  142.  
  143.       /* Check which IDCMP flag was sent: */
  144.       if( class == CLOSEWINDOW )
  145.         close_me=TRUE; /* The user selected the Close window gadget! */  
  146.     }
  147.   }
  148.  
  149.  
  150.  
  151.   /* We should always close the windows we have opened before we leave: */
  152.   CloseWindow( my_window );
  153.  
  154.  
  155.  
  156.   /* Close the Intuition Library since we have opened it: */
  157.   CloseLibrary( IntuitionBase );
  158.   
  159.   /* THE END */
  160. }
  161.